﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.ADF.BaseClasses;
using PlanningGIS.Framework;
using PlanningGIS.Engine.Controls;

namespace PlanningGIS.TocContextMenu
{
    /// <summary>
    /// 关联图表
    /// </summary>
    public class JoinAndRelate : BaseCommand
    {        
        /// <summary>
        /// 构造函数
        /// </summary>
        public JoinAndRelate()
        {
            base.m_caption = "关联图表";
            base.m_toolTip = base.Caption;
        }

        /// <summary>
        /// 应用程序
        /// </summary>
        IApplication m_Application = null;

        /// <summary>
        /// 创建按钮
        /// </summary>
        /// <param name="hook"></param>
        public override void OnCreate(object hook)
        {
            if (m_Application == null)
            {
                m_Application = hook as IApplication;
            }
        }

        /// <summary>
        /// 点击事件
        /// </summary>
        public override void OnClick()
        {
            ILayer pLayer = (m_Application as IFramework).TOCControl.CustomProperty as ILayer;
            if (pLayer is IFeatureLayer)
            {
                FrmJoins frmJoin = new FrmJoins(pLayer as IFeatureLayer);
                frmJoin.Hook = (m_Application as IFramework).Object;
                frmJoin.ShowDialog();               
            }
        }

        /// <summary>
        /// 是否可用
        /// </summary>
        public override bool Enabled
        {
            get
            {
                if (m_Application == null) return false;
                return (m_Application as IFramework).IsMapCtrlactive;
            }
        }
        
    }

}
